package com.sd.activity;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class SampleFileActivity extends Activity{

	private static final String TAG = "MyExplorerDemo";
	private static final int REQUEST_EX = 1;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		Button button = (Button) findViewById(R.id.button1);
		button.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.putExtra("explorer_title","文件管理");
				intent.setDataAndType(Uri.fromFile(new File("/sdcard")), "*/*");
				intent.setClass(SampleFileActivity.this, FilesActivity.class);
				startActivityForResult(intent, REQUEST_EX);
			}
		});
	}

	protected void onActivityResult(int requestCode, int resultCode,
			Intent intent) {
		String path;
		if (resultCode == RESULT_OK) {
			if (requestCode == REQUEST_EX) {
				Uri uri = intent.getData();
				TextView text = (TextView) findViewById(R.id.text);
				String url = uri.toString();
				int point = url.lastIndexOf(".");
				text.setText("select: " + url.substring(point));
			}
		}
	}
}
